package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/type/{type}")
    public Result selectByType(@PathVariable Integer type){
        List<Activity> activity= activityService.selectByType(type);
        return Result.success(activity);
    }


    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        activityService.updateActivity(activity);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        activityService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        Activity activity= activityService.selectById(id);
        return Result.success(activity);
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        activityService.addActivity(activity);
        return Result.success();
    }

    @GetMapping
    public Result page(Integer channel, Integer type, Integer status,
                       @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<Activity> pageResult = activityService.page(channel,type,status,page,pageSize);
        return Result.success(pageResult);
    }
}
